/**
 * Created by chocolate on 16/5/22.
 */

//引入系统模块
import React, {
  Component,
  StyleSheet,
  View,
  WebView,
  ActivityIndicatorIOS,
  Text,
} from 'react-native';

var Title =require('./Title');
class NoticeScreen extends Component {
  constructor(props) {
    super(props);
    this.state = {
      htmlContent: this.props.notice.content,
      isLoading:true
    };
  }

 componentDidMount(){
    this.setState({isLoading:false});
  }

  _onPressReturn(){
    this.props.navigator.pop();
  }

  renderProcessor(){
    return(
        <View style={{flex:1,backgroundColor:'#2981b1',alignItems:'center',justifyContent:'center'}}>
            <ActivityIndicatorIOS
                hidden='true'
                size='large'/> 
            <Text style={{color:'#fff'}}>正在努力加载中...</Text>
        </View>
    )
  }

  renderMain(){
    var HTML = '<!DOCTYPE html><html><head></head><body>' + this.state.htmlContent
      + '</body></html>';
    return (
      <View style={styles.container}>
        <Title title={{left:"返回",center:"公告内容",leftAct:this._onPressReturn.bind(this)}}></Title>
        <WebView source={{html:HTML}}/>
      </View>
    )
  }

  render() {
    var display = this.state.isLoading ?(this.renderProcessor()):( this.renderMain());
    return(
      <View style={styles.container}>
          {display}
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    backgroundColor: '#fff',
    flex: 1,
  },
})
module.exports = NoticeScreen;